package com.dzz.sjgl.jpa;

import com.dzz.sjgl.entity.SentenceInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * @author KRIC
 */
public interface SentenceRepository extends JpaRepository<SentenceInfo, Integer>, JpaSpecificationExecutor<SentenceInfo>, Serializable {

    @Query(value = " SELECT s.paper_id,p.name " +
            "FROM sentence_info s LEFT JOIN paper_info p ON s.paper_id= p.id " +
            "WHERE s.sentence LIKE CONCAT('%',:word,'%') " +
            "GROUP BY s.paper_id,p.name ", nativeQuery = true)
    List<Map<String, String>> getCount(@Param("word") String word);

    @Modifying
    @Transactional
    @Query(value = "delete from SentenceInfo e where e.paperId in (:ids) ")
    int del(@Param("ids") List<Integer> ids);

    @Modifying
    @Transactional
    @Query(value = "delete from SentenceInfo e where e.sentence like '%*%' or e.sentence like '%\\_%' OR e.sentence like '%()%' OR e.sentence like '%( )%'")
    int delDirtyData();
}
